<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>待开发票</title>
    <link rel="stylesheet" href="../../layuiadmin/layui-v2.5.5/layui/css/layui.css" media="all" type="text/css">
    <link rel="stylesheet" href="../../layuiadmin/js/finance/js/bootstrap/css/bootstrap.min.css" />
    <script type="text/javascript" src="../../layuiadmin/js/finance/js/jquery.min.js" ></script>
    <script type="text/javascript" src="../../layuiadmin/js/finance/js/bootstrap/js/bootstrap.js" ></script>
    <script type="text/javascript" src="../../layuiadmin/js/finance/js/jquery.cookie.js"></script>
    <script src="../../layuiadmin/layui-v2.5.5/layui/layui.js" type="text/javascript"></script>
    <script src="../../layuiadmin/layui-v2.5.5/layui/css/layui.css" charset="utf-8"></script>
    <script>
        $(document).ready(function () {
            $("#divshow").hide();
            $.post("http://localhost:8080/financeInvoiceController/openproject",function(msg) {
                for(var i=0;i<msg.length;i++){
                    var openproject=$("#projectId");
                    var op=$("<option value='"+msg[i].openProjectId+"'>"+msg[i].project+"</option>");
                    openproject.append(op);
                }
            });
            $.post("http://localhost:8080/financeInvoiceController/invoicetypelist",function(msg) {
                for(var i=0;i<msg.length;i++){
                    var invoicetype=$("#invoiceTypeId");
                    var op=$("<option value='"+msg[i].invoiceTypeId+"'>"+msg[i].invoiceType+"</option>");
                    invoicetype.append(op);
                }
            });
            demo();

        });
        function show() {
            if ($("#open").val() == "展开") {
                $("#divshow").show();
                $("#open").val("收起");
            } else {
                $("#divshow").hide();
                $("#open").val("展开");
            }
        }

        function check() {
            var caseid1= $('input[name="an"]:checked').parent().parent().find("td").eq(1).text();
            var caseid=$("#caseid").val(caseid1);
            var cookie=$.cookie("redisName");
            $.post("http://localhost:8080/financeIncomeController/caselist",{"caseid":caseid1},function(msg) {
                $.post("http://localhost:8080/financeInvoiceController/getByCase",{"caseId":caseid1},function (data) {
                    $.post("http://localhost:8080/financeIncomeController/user", {"username":cookie}, function (msg1) {
                        $.post("http://localhost:8080/financeIncomeController/user", {"username":cookie}, function (data1) {
                                var mainLawyer = $("#mainLawyer").val(msg.mainLawyer.empName);
                                var clientId = $("#clientId").text(msg.clientId.clientName);
                                var causeOfAction = $("#causeOfAction").text(msg.causeOfAction);
                                var agencyMoney = $("#agencyMoney").text(msg.agencyMoney + "(元)");
                                var realityMoney = $("#realityMoney").text(msg.realityMoney + "(元已经收到的钱)");
                                var lawyer = $("#lawyer").text(msg.mainLawyer.empName);
                                var invoiceTitle = $("#invoiceTitle").val(data1.hrEmp.empName);
                                for (var i = 0; i < data.length; i++) {
                                    var money = "";
                                    money += data[i].invoiceMoney;
                                    var yiinvoiceMoney = $("#yiinvoiceMoney").text(money + "(已经开过的发票)");
                                }
                        });
                    });
                });

            });
        }
        function demo() {
            var sel=$("#sel").val();
            var name=$("#name").val();
            $.post("http://localhost:8080/financePayoutController/caselawlist",
                {"name":name,"sel":sel},
                function(msg){
                    var tab=$("#tab");
                    if (msg.length == 0) {
                        $("#tab  tr:not(:first)").remove();
                        var tr = $("<tr></tr>");
                        var td = $("<td colspan='7'>没有相关数据</td>");
                        tr.append(td);
                        tab.append(tr);
                    }else {
                        $("#tab  tr:not(:first)").remove();
                        for(var i=2;i<msg.length;i++){
                            var tr = $("<tr></tr>");
                            var td = $("<td><input type='radio' id='ca'  name='an' ></td>");
                            var td1 = $("<td>" + msg[i].caseId + "</td>");
                            var td2 = $("<td>" + msg[i].clientId.clientName + "</td>");
                            var td3 = $("<td>" + msg[i].oppositeId.clientName + "</td>");
                            var td4 = $("<td>" + msg[i].mainLawyer.empName + "</td>");
                            var td5 = $("<td>" + msg[i].closeDate + "</td>");
                            var td6=$("<td class='hidden'>"+msg[i].amountMoney+"</td>");
                            tr.append(td);
                            tr.append(td1);
                            tr.append(td2);
                            tr.append(td3);
                            tr.append(td4);
                            tr.append(td5);
                            tr.append(td6);
                            tab.append(tr);
                        }
                    }
                });
        }
        function add() {
            var caseid=$("#caseid").val();
            var invoiceTitle=$("#invoiceTitle").val();
            var invoiceMoney=$("#invoiceMoney").val();
            var projectId=$("#projectId").val();
            var openType=$("#openTypeId").val();
            var invoiceTypeId=$("#invoiceTypeId").val();
            var taxPayerIdemtity=$("#taxPayerIdemtity").val();
            var invoiceNumber=$("#invoiceNumber").val();
            var invoiceDate=$("#invoiceDate").val();
            var basicBank=$("#basicBank").val();
            var accountNumber=$("#accountNumber").val();
            var registerdAddress=$("#registerdAddress").val();
            var fixedlineTelephone=$("#fixedlineTelephone").val();
            var applicationRemark=$("#applicationRemark").val();
            var invoiceRemark=$("#invoiceRemark").val();
            if(caseid!=null&&caseid!=''&&invoiceTitle!=null&&invoiceTitle!=''&&
                invoiceMoney!=null&&invoiceMoney!=''&&projectId!=null&&projectId!=''&&
                openType!=null&&openType!=''&& invoiceTypeId!=null&&invoiceTypeId!=''&&
                taxPayerIdemtity!=null&&taxPayerIdemtity!=''&& invoiceNumber!=null&&invoiceNumber!=''&&
                invoiceDate!=null&&invoiceDate!='') {
                $.post("http://localhost:8080/financeInvoiceController/add",
                    {
                        "caseid": caseid, "invoiceTitle": invoiceTitle,
                        "invoiceMoney": invoiceMoney, "projectId": projectId,
                        "openType": openType, "invoiceTypeId": invoiceTypeId,
                        "taxPayerIdemtity": taxPayerIdemtity, "invoiceNumber": invoiceNumber,
                        "invoiceDate": invoiceDate,
                        "basicBank":basicBank,"accountNumber":accountNumber,
                        "registerdAddress":registerdAddress,"fixedlineTelephone":fixedlineTelephone,
                        "applicationRemark":applicationRemark,"invoiceRemark":invoiceRemark,
                    },
                    function (msg) {
                        if(msg>0){
                            alert("提交成功")
                        }else{
                            alert("请重新填写")
                        }
                    });
            }else{
                alert("请填写完整信息");
            }
        }
    </script>
</head>
<body>
<div class="container-fluid">
    <form class="form-horizontal form-inline" enctype="multipart/form-data" method="post">
        <div style="margin-top: 15px">
            <div class="row">
                <div class="col-lg-12">
                    <div class="col-lg-1"></div>
                    <div class="col-lg-11">
                        <font style="font-size: 20px"><strong>|代开发票</strong></font><br>
                    </div>
                </div>
                <div class="col-lg-12">
                    <br>
                    <div class="col-lg-1"></div>
                    <div class="col-lg-5">
                        <label for="caseid"><font style="color: red">*</font>案件</label>
                        <br>
                        <input type="text"  data-toggle="modal" data-target="#mt" class="form-control" style="width:100%" id="caseid" readonly="readonly">
                    </div>
                    <div class="col-lg-6">
                        <label><font style="color: red">*</font>申请人:</label>
                        <br>
                        <input type="text" class="form-control" style="width:100%" id="mainLawyer" readonly="readonly">
                    </div>
                </div>
                <div class="col-lg-12">
                    <br>
                    <div class="col-lg-1"></div>
                    <div class="col-lg-5">
                        <label ><font style="color: red">*</font>委托人：</label><span id="clientId"></span>
                        <br>
                    </div>
                    <div class="col-lg-6">
                        <label><font style="color: red">*</font>案由：</label><span id="causeOfAction"></span>
                        <br>
                    </div>
                </div>
                <div class="col-lg-12">
                    <br>
                    <div class="col-lg-1"></div>
                    <div class="col-lg-5">
                        <label ><font style="color: red">*</font>代理费：</label><span id="agencyMoney"></span>
                        <br>
                    </div>
                    <div class="col-lg-6">
                        <label><font style="color: red">*</font>已到款项：</label><span id="realityMoney"></span>
                        <br>
                    </div>
                </div>
                <div class="col-lg-12">
                    <br>
                    <div class="col-lg-1"></div>
                    <div class="col-lg-5">
                        <label ><font style="color: red">*</font>已开票：</label><span id="yiinvoiceMoney"></span>
                        <br>

                    </div>
                    <div class="col-lg-6">
                        <label><font style="color: red">*</font>办案律师：</label><span id="lawyer"></span>
                        <br>
                    </div>
                </div>
                <div class="col-lg-12">
                    <br>
                    <div class="col-lg-1"></div>
                    <div class="col-lg-5">
                        <label for="caseid"><font style="color: red">*</font>发票抬头：</label>
                        <br>
                        <input type="text" class="form-control" style="width:100%" id="invoiceTitle" readonly="readonly">
                    </div>
                    <div class="col-lg-6">
                        <label><font style="color: red">*</font>开票金额：</label>
                        <br>
                        <input type="text" class="form-control" style="width:100%" id="invoiceMoney">
                    </div>
                </div>
                <div class="col-lg-12">
                    <br>
                    <div class="col-lg-1"></div>
                    <div class="col-lg-5">
                        <label for="projectId"><font style="color: red">*</font>开票项目:</label>
                        <br>
                        <select id="projectId" class="form-control" style="width:100%">
                            <option value="-1">请选择开票项目</option>
                        </select>
                    </div>
                    <div class="col-lg-6">
                        <label for="openTypeId"><font style="color: red">*</font>开具类型:</label>
                        <br>
                        <select id="openTypeId" class="form-control" style="width:100%">
                            <option value="-1">请选择开具类型</option>
                            <option value="1">企业</option>
                            <option value="2">个人</option>
                        </select>
                    </div>
                </div>
                <div class="col-lg-12">
                    <br>
                    <div class="col-lg-1"></div>
                    <div class="col-lg-5">
                        <label for="invoiceTypeId"><font style="color: red">*</font>发票类型:</label>
                        <br>
                        <select id="invoiceTypeId" class="form-control" style="width:100%">
                            <option value="-1">请选择发票类型</option>
                        </select>
                    </div>
                    <div class="col-lg-6">
                        <label for="taxPayerIdemtity"><font style="color: red">*</font>纳税人识别号:</label>
                        <br>
                        <input type="text" class="form-control" style="width:100%" id="taxPayerIdemtity">
                    </div>
                </div>
                <div class="col-lg-12">
                    <br>
                    <div class="col-lg-1"></div>
                    <div class="col-lg-5">
                        <label for="invoiceNumber"><font style="color: red">*</font>发票号</label>
                        <br>
                        <input type="text" class="form-control" style="width:100%" id="invoiceNumber">
                    </div>
                    <div class="col-lg-6">
                        <label for="invoiceDate"><font style="color: red">*</font>开票日期</label>
                        <br>
                        <input type="date" class="form-control" style="width:100%" id="invoiceDate">
                    </div>
                </div>
                <!--选填-->
                <div class="col-lg-12">
                    <br>
                    <div class="col-lg-1"></div>
                    <div class="col-lg-5">
                        <font style="font-size: 20px"><strong>|其他选填&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</strong></font>
                        <input type="button" value="展开" class="btn btn-default btn-sm" onclick="show()" id="open"/>
                    </div>
                </div>
                <div id="divshow">
                    <div class="col-lg-12">
                        <br>
                        <div class="col-lg-1"></div>
                        <div class="col-lg-5">
                            <label for="accountNumber">基本开户账号</label>
                            <br>
                            <input type="text" class="form-control" style="width:100%" id="accountNumber">
                        </div>
                        <div class="col-lg-6">
                            <label for="registerdAddress">注册场所地址</label>
                            <br>
                            <input type="text" class="form-control" style="width:100%" id="registerdAddress">
                        </div>
                    </div>
                    <div class="col-lg-12">
                        <br>
                        <div class="col-lg-1"></div>
                        <div class="col-lg-5">
                            <label for="fixedlineTelephone">注册固定电话</label>
                            <br>
                            <input type="text" class="form-control" style="width:100%" id="fixedlineTelephone">
                        </div>
                        <div class="col-lg-6">
                            <label for="basicBank">基本开户银行</label>
                            <br>
                            <input type="text" class="form-control" style="width:100%" id="basicBank">
                        </div>
                    </div>
                    <div class="col-lg-12">
                        <br>
                        <div class="col-lg-1"></div>
                        <div class="col-lg-11">
                            <label for="applicationRemark">申请备注</label>
                            <br>
                            <textarea class="form-control" style="width:100%" id="applicationRemark"></textarea>
                        </div>
                    </div>
                    <div class="col-lg-12">
                        <br>
                        <div class="col-lg-1"></div>
                        <div class="col-lg-11">
                            <label for="invoiceRemark">开票备注</label>
                            <br>
                            <textarea class="form-control" style="width:100%" id="invoiceRemark"></textarea>
                        </div>
                    </div>
                </div>
                <div>
                    <div class="col-lg-12">
                        <br>
                        <div class="col-lg-1"></div>
                        <div class="col-lg-11">
                            <button type="button" class="btn btn-primary" onclick="add()">确认提交</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal"  id="mt">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <span>选择案件</span>
                        <button class="close" data-dismiss="modal">
                            <span>&times;</span>
                        </button>
                    </div>
                    <div class="modal-body" style="height: 500px">
                        <div class="row"  style="padding-left: 20px" >
                            <input type="text" class="form-control" id="name"/>
                            <select class="form-control" id="sel">
                                <option value="-1">请选择</option>
                                <option value="1">案号搜索</option>
                                <option value="2">承办律师搜索</option>
                                <option value="3">委托人搜索</option>
                                <option value="4">对方当事人搜索</option>
                                <option value="5">案由搜索</option>
                                <option value="6">受理法院搜索</option>
                            </select>&nbsp;&nbsp;
                            <input type="button" class="btn btn-primary" value="搜索" onclick="demo()">
                        </div>
                        <div class="row"  style="padding-left: 20px;margin-top: 30px;" >
                            <table style="width: 97%;border: none;text-align: center" border="1px" id="tab">
                                <tr style="height: 50px">
                                    <td><b>选择</b></td>
                                    <td><b>案件号</b></td>
                                    <td><b>委托人</b></td>
                                    <td><b>对方当事人</b></td>
                                    <td><b>承办律师</b></td>
                                    <td><b>收案日期</b></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <input type="button" class="btn btn-primary"  value="确定" data-dismiss="modal" onclick="check()">
                        <input type="button" class="btn btn-primary" value="关闭" data-dismiss="modal">
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
</body>
</html>